<?php
/**
 * [PHPFOX_HEADER]
 * 
 * @copyright		[PHPFOX_COPYRIGHT]
 * @author  		Raymond Benc
 * @package 		Phpfox
 * @version 		$Id: profile.html.php 4626 2012-09-12 11:17:50Z Raymond_Benc $
 */
defined('PHPFOX') or exit('NO DICE!');
?>

{if count($aSettings)}

<div id="js_custom_public_message" class="public_message" style="margin-bottom:10px;">
    <a href="{url link='profile'}">{phrase var='user.view_your_updated_profile'}</a>
</div>

{*<form method="post" action="{url link='user.profile'}"{if !$bIsEdit} onsubmit="{plugin call='user.template_controller_profile_form_onsubmit'} $('#js_custom_public_message').hide(); $('#js_custom_submit_button').attr('disabled', true).addClass('disabled'); $('#js_custom_update_info').html($.ajaxProcess('{phrase var='user.updating_profile' phpfox_squote=true}')).show(); $(this).ajaxCall('custom.updateFields'); return false;"{/if}>*}
<form enctype="multipart/form-data" target="update_profile" method="post" action="{url link='user.updateprofile'}"{if !$bIsEdit} onsubmit="{plugin call='user.template_controller_profile_form_onsubmit'} $('#js_custom_public_message').hide(); $('#js_custom_submit_button').attr('disabled', true).addClass('disabled'); $('#js_custom_update_info').html($.ajaxProcess('{phrase var='user.updating_profile' phpfox_squote=true}')).show(); $(this).ajaxCall('custom.updateFields'); return false;"{/if}>        
    
    {if isset($iUserId)}
      <div><input type="hidden" name="id" value="{$iUserId}" /></div>
    {/if}
    <div class="table js_custom_groups js_custom_group_basic">
        <div class="title_group">
            <h2>Edit Account Setting</h2>
        </div>
        {if Phpfox::getUserParam('user.can_change_email') }
        <div class="table">
            <div class="table_left">
                <label for="email">{phrase var='user.email_address'}:</label>
            </div>
            <div class="table_right">
                <input type="text" {if Phpfox::getParam('user.verify_email_at_signup')}onfocus="$('#js_email_warning').show();" {/if}name="val[email]" id="email" value="{value type='input' id='email'}" size="30" />
                       {if Phpfox::getParam('user.verify_email_at_signup')}
                       <div class="extra_info" style="display:none;" id="js_email_warning">
                    {phrase var='user.changing_your_email_address_requires_you_to_verify_your_new_email'}
                </div>
                {/if}
            </div>
            <div class="clear"></div>
        </div>
        {/if}
        {if !Phpfox::getUserBy('fb_user_id')}
        <div class="table">
            <div class="table_left">
                <label for="password">{phrase var='user.password'}:</label>
            </div>
            <div class="table_right">
                <div id="js_password_info" style="padding-top:2px;"><a class="button" href="#" onclick="tb_show('{phrase var='user.change_password' phpfox_squote=true}', $.ajaxBox('user.changePassword', 'height=250&amp;width=500')); return false;">{phrase var='user.change_password'}</a></div>
            </div>
            <div class="clear"></div>
        </div>
        {/if}
        {if Phpfox::getUserParam('user.can_edit_gender_setting')}
        <div class="table">
            <div class="table_left">
                <label for="gender">{phrase var='user.gender'}:</label>
            </div>
            <div class="table_right">
                {select_gender}
            </div>
            <div class="clear"></div>
        </div>
        {/if}       
        
        {if Phpfox::getParam('user.enable_relationship_status') && Phpfox::getUserParam('custom.can_have_relationship') && isset($aRelations) && !empty($aRelations)}
        <div class="table">
            <div class="table_left">
                {phrase var='custom.relationship_status'}
            </div>
            <div class="table_right">
                <select name="val[relation]" id="relation" onchange="$Behavior.displayRelationshipChange()">
                    {foreach from=$aRelations item=aRelation}
                    <option value="{$aRelation.relation_id}" {if isset($aForms.relation_id) && $aForms.relation_id == $aRelation.relation_id} selected="selected"{/if}>{phrase var=$aRelation.phrase_var_name} </option>
                    {/foreach}
                </select>

                <script type="text/javascript">
                    var aRelationshipChange = {$sJsArray};
					
                    {if isset($aForms.relation_id)}
                    $('#relation').val({$aForms.relation_id});
                    {/if}
                </script>

                <span id="relation_with">
                    <span class="js_relation_with_message" id="relation_with_message_to" style="display:none;">{phrase var='user.to'}:</span>
                    <span class="js_relation_with_message" id="relation_with_message_with" style="display:none;">{phrase var='user.with'}:</span>
                    <div class="edit_friend_relation">
                        <span id="js_custom_search_friend"></span>	
                        <span id="sFriendImage">
                            {if isset($aForms.with_user) && isset($aForms.with_user.user_image) &&  !empty($aForms.with_user) && $aForms.with_user.with_user_id > 0}
                            {img user=$aForms.with_user suffix='_50_square' max_height=50 max_height=50}
                            {/if}
                        </span>
                        {if isset($aForms.with_user.user_id) && !empty($aForms.with_user.user_id)}
                        <input type="hidden" id="relation_with_input_hidden" name="val[relation_with]" value="{$aForms.with_user.user_id}">
                        {/if}
                        <div id="js_custom_search_friend_placement"></div>

                        <input type="hidden" name="val[previous_relation_with]" value="{if isset($aForms.with_user.user_id)}{$aForms.with_user.user_id}{else}0{/if}">
                        <input type="hidden" name="val[previous_relation_type]" value="{if isset($aForms.relation_id)}{$aForms.relation_id}{else}0{/if}">
                        {if isset($aForms.with_user.status_id) && $aForms.with_user.status_id == 1}
                        <div style="margin-left:60px;">{phrase var='user.pending_confirmation'}</div>
                        {/if}
                    </div>
                    {literal}
                    <script type="text/javascript">
                        $Core.searchFriends({
                            'id': '#js_custom_search_friend',
                            'placement': '#js_custom_search_friend_placement',
                            'width': '300px',
                            'max_search': 10,
                            'input_name': 'friends',
                            'default_value': {/literal}{if isset($aForms.with_user) && $aForms.with_user.with_user_id > 0}'{$aForms.with_user.full_name}' {else} '{phrase var='user.search_friends_by_their_name'}'{/if}{literal},
                            'search_input_id' : 'sFriendInput',
                            'onclick': function()
                            {																	
                                return false;
                            },
                            'onBeforePrepend' : function()
                            {
                                console.log('run here');
                                $('#sFriendInput').val($Core.searchFriendsInput.aFoundUser['full_name']);
                                $Core.searchFriendsInput.sHtml = '';
                                if ($('#sFriendImage').length < 1)
                                {
                                    $('#sFriendInput').before('<span id="sFriendImage"></span>');
                                }
                                $('#sFriendImage').html('<span style=""><img src="'+$Core.searchFriendsInput.aFoundUser['user_image'] + '"></span>');
                                $('#js_custom_search_friend_placement').hide();
									
                                /* Make sure there's only one input with the name 
                                 * -safe check for when user doesnt reload the page like in ajax browsing- */
                                if ($('#relation_with_input_hidden').length > 0)
                                {
                                    $('#relation_with_input_hidden').remove();
                                }
                                if ($('#relation_with_input_hidden').length < 1)
                                {
                                    $('#sFriendImage').after('<input type="hidden" id="relation_with_input_hidden" name="val[relation_with]" value="' + $Core.searchFriendsInput.aFoundUser['user_id'] + '">');
                                }
                                else
                                {
                                    $('#relation_with_input_hidden').val($Core.searchFriendsInput.aFoundUser['user_id']);
                                }
                            }
                        });
                        $Core.loadInit();
                    </script>
                    {/literal}



                </span>
            </div>
        </div>
        {/if}
        {if Phpfox::getUserParam('user.can_edit_dob')}
        <div class="table">
            <div class="table_left">
                {phrase var='user.date_of_birth'}:
            </div>
            <div class="table_right">
                {select_date start_year=$sDobStart end_year=$sDobEnd field_separator=' / ' field_order='MDY' bUseDatepicker=false sort_years='DESC'}
            </div>
            <div class="clear"></div>
        </div>
        {/if}
        
        <!--Full Name-->
        <div class="title_group">
            <h2>Profile Info</h2>
        </div>
		{if Phpfox::getUserId() == $aForms.user_id && Phpfox::getUserParam('user.can_change_own_full_name')}
		
		{if Phpfox::getParam('user.split_full_name')}
		<div><input type="hidden" name="val[full_name]" id="full_name" value="{value type='input' id='full_name'}" size="30" /></div>
		<div class="table">
			<div class="table_left">
				<label for="first_name">{phrase var='user.first_name'}:</label>
			</div>
			<div class="table_right">
				<input type="text" name="val[first_name]" id="first_name" value="{value type='input' id='first_name'}" size="30" {if $iTotalFullNameChangesAllowed != 0 && $aForms.total_full_name_change >= $iTotalFullNameChangesAllowed}readonly="readonly"{/if} />
			</div>			
		</div>		
		<div class="table">
			<div class="table_left">
				<label for="last_name">{phrase var='user.last_name'}:</label>				
			</div>
			<div class="table_right">
				<input type="text" name="val[last_name]" id="last_name" value="{value type='input' id='last_name'}" size="30" {if $iTotalFullNameChangesAllowed != 0 && $aForms.total_full_name_change >= $iTotalFullNameChangesAllowed}readonly="readonly"{/if} />
			</div>			
		</div>		
		
		{else}		
		<div class="table">
			<div class="table_left">
				<label for="full_name">Full name:</label>
			</div>
			<div class="table_right">
				<input type="text" name="val[full_name]" id="full_name" value="{value type='input' id='full_name'}" size="30" />
			</div>
			<div class="clear"></div>
		</div>
		{/if}
		{/if}
            <!-- End first name -->
            
        <div class="table">
            <div class="table_left">
                <label for="country_iso">Avatar:</label>
            </div>
            <div class="table_right">
               {img user=$aForms suffix='_200_square' max_width=200 max_height=200}
               <div class="js_uploader_files"><input type="file" size="30" class="js_uploader_files_input" name="image"></div>
            </div>
            <div class="clear"></div>
        </div>
            
            <div class="table">
            <div class="table_left">
                <label for="country_iso">{phrase var='user.location'}:</label>
            </div>
            <div class="table_right">
                {select_location}
                {if $isEditProfile }
                {module name='core.country-child' country_force_div=true}
                {else}
                {module name='core.country-child'}
                {/if}

            </div>
            <div class="clear"></div>
        </div>

        <div class="table">
            <div class="table_left">
                <label for="city_location">{phrase var='user.city'}:</label>
            </div>
            <div class="table_right">
                <input type="text" name="val[city_location]" id="city_location" value="{value type='input' id='city_location'}" size="30" />
            </div>
            <div class="clear"></div>
        </div>
            <div style="display:none;">
        <div class="table" >
            <div class="table_left">
                <label for="postal_code">{phrase var='user.zip_postal_code'}:</label>
            </div>
            <div class="table_right">
                <input type="text" name="val[postal_code]" id="postal_code" value="{value type='input' id='postal_code'}" size="10" />
            </div>
            <div class="clear"></div>
        </div>

        <div class="separate"></div>


        {if Phpfox::isModule('forum')}
        <div class="separate"></div>		
        <div class="table">
            <div class="table_left">
                {phrase var='user.forum_signature'}:
            </div>
            <div class="table_right">
                <textarea cols="40" rows="5" id="signature" name="val[signature]">{$aForms.signature}</textarea>
            </div>
            <div class="clear"></div>
        </div>		
        {/if}

        {if Phpfox::isModule('feed') && Phpfox::getParam('feed.timeline_optional')}
        <div class="separate"></div>		
        <div class="table">
            <div class="table_left">
                {phrase var='user.timeline'}:
            </div>
            <div class="table_right">
                <select name="val[use_timeline]">
                    <option value="0"{value id='use_timeline' type='select' default=0}>{phrase var='user.no'}</option>
                    <option value="1"{value id='use_timeline' type='select' default=1}>{phrase var='user.yes'}</option>
                </select>
            </div>
            <div class="clear"></div>
        </div>			
        {/if}

        {if Phpfox::getParam('profile.allow_user_select_landing')}
        {if Phpfox::isModule('feed') && !Phpfox::getParam('feed.timeline_optional')}
        <div class="separate"></div>		
        {/if}
        <div class="table">
            <div class="table_left">
                {phrase var='user.landing_page'}:
            </div>
            <div class="table_right">
                <select name="val[landing_page]">
                    <option value="wall"{value id='landing_page' type='select' default='wall'}>{phrase var='user.wall'}</option>
                    <option value="info"{value id='landing_page' type='select' default='info'}>{phrase var='user.profile_info'}</option>
                </select>
            </div>
            <div class="clear"></div>
        </div>		
        {/if}
        </div>
    </div>

    {foreach from=$aSettings item=aSetting}
    <div class="table js_custom_groups js_custom_group_{$aSetting.group_id}" >
        <div class="table_left">
            {if $aSetting.is_required}{/if}{phrase var=$aSetting.phrase_var_name}:
        </div>
        <div class="table_right">
            {template file='custom.block.form'}
        </div>
    </div>
    {/foreach}
    {plugin call='user.template_controller_profile_form'}
    <div class="table_clear">
        <input type="submit" value="{phrase var='user.update'}" class="button" id="js_custom_submit_button"> <span id="js_custom_update_info"></span>
    </div>
    <iframe id="update_profile" name="update_profile" style="display:none;"></iframe>
</form>

{else}
<div class="extra_info">
    {phrase var='user.no_custom_fields_have_been_added'}
    {if Phpfox::getUserParam('custom.can_add_custom_fields')}
    <ul class="action">
        <li><a href="{url link='admincp.custom.add'}">{phrase var='user.add_a_new_custom_field'}</a></li>
    </ul>
    {/if}
</div>
{/if}
